﻿using System;
using System.Globalization;
using Business;
using Entity;
using UI_MasterPage;

namespace UI_Main
{
    public partial class PresentationEditArticle : System.Web.UI.Page
    {
        private ArticleBusiness _articleBusiness;
        protected void Page_Init(object sender, EventArgs e)
        {
            var masterPage = (PresentationMain) Master;
            if (masterPage != null) _articleBusiness = masterPage.ArticleBusiness;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["Id"] == null)
                {
                    Response.Redirect("Default.aspx");
                }
                else
                {
                    var article = _articleBusiness.GetById(Guid.Parse(Request.QueryString["Id"].ToString(CultureInfo.InvariantCulture)));
                    txtBody.Text = article.Content;
                    txtBody.Attributes.Add("key", article.Id.ToString());
                }
            }
        }

        protected void UpdateClick(object sender, EventArgs e)
        {
            Guid id = Guid.Parse(txtBody.Attributes["key"]);
            string content = txtBody.Text;
            string title = "kaka";
            _articleBusiness.Update(id, title, content, null, new Guid(), null);
        }
    }
}